package com.jzoffer2;

import ds.TreeNode;

/**
 * TODO
 *
 * @author lefly
 * @version 1.0
 * @classname No55
 * @description
 * @date 2021/2/4 下午2:45
 */
public class No55 {

    public static void main(String[] args) {
        TreeNode t1 = new TreeNode(3);
        TreeNode t2 = new TreeNode(9);
        TreeNode t3 = new TreeNode(20);
        TreeNode t4 = new TreeNode(15);
        TreeNode t5 = new TreeNode(7);
        t1.left = t2;
        t1.right = t3;
        t3.left = t4;
        t3.right = t5;
        int res = maxDepth(t1);
        System.out.println(res);
    }

    public static int maxDepth(TreeNode root) {
        if(root == null){
            return 0;
        }
        int leftDepth = maxDepth(root.left);
        int rightDepth = maxDepth(root.right);
        return (leftDepth > rightDepth ? leftDepth : rightDepth) + 1;

    }

}
